//
//  CustomButton.m
//  自定义Button图文上下
//
//  Created by 殷殷明静 on 16/9/26.
//  Copyright © 2016年 YMJ. All rights reserved.
//

#import "CustomButton.h"


@implementation CustomButton
- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat midX = self.frame.size.width / 2;
    CGFloat midY = self.frame.size.height / 2;
    self.titleLabel.center = CGPointMake(midX, midY + 24); /*修改上下间距*/
    self.imageView.center = CGPointMake(midX, midY - 19);
    
}
- (void)verticalImageAndTitle:(CGFloat)spacing
{

    CGSize imageSize = self.imageView.frame.size;
    CGSize titleSize = self.titleLabel.frame.size;
    CGSize textSize = [self.titleLabel.text sizeWithAttributes:@{NSFontAttributeName:self.titleLabel.font}];
    CGSize frameSize = CGSizeMake(ceilf(textSize.width), ceilf(textSize.height));
    if (titleSize.width + 0.5 < frameSize.width) {
        titleSize.width = frameSize.width;
    }
    CGFloat totalHeight = (imageSize.height + titleSize.height + spacing);
    self.imageEdgeInsets = UIEdgeInsetsMake(- (totalHeight - imageSize.height), 0.0, 0.0, - titleSize.width);
    self.titleEdgeInsets = UIEdgeInsetsMake(0, - imageSize.width, - (totalHeight - titleSize.height), 0);
    
}

@end
